<?php
// php by Fahri
include '../config/db_config.php';
include '../lib/kelola_produk.php';
include '../lib/kelola_gambar.php';
include '../lib/kelola_review.php';
include '../lib/kelola_technopreneur.php';

$kelola_produk = new kelola_produk();
$kelola_gambar = new kelola_gambar();
$kelola_review = new kelola_review();
$kelola_technopreneur = new kelola_technopreneur();

if(!isset($_GET['id'])){
	header('location:tampilan_home.php');
}

$id_produk = htmlspecialchars($_GET['id'], ENT_QUOTES);

if(isset($_POST['email']) && isset($_POST['review'])){
	$email = htmlspecialchars($_POST['email'], ENT_QUOTES);
	$review = nl2br(htmlspecialchars($_POST['review'], ENT_QUOTES));	
	
	$data = array(
		'ID_PRODUK' => $id_produk,
		'EMAIL_GUEST' => $email,
		'REVIEW_PRODUK' => $review,
		'WAKTU' => date('Y-m-d'),
		'CONFIRMED' => 0
	);
	
	$kelola_review->insert_review($data);
}


$result = $kelola_produk->select_produk($id_produk);

if(mysql_num_rows($result) == 0){
	header('location:tampilan_home.php');
}

$produk;
while ($row = mysql_fetch_assoc($result)) {
	$produk = $row;
	//var_dump($row);
}

$result = $kelola_gambar->select_gambar($id_produk);

while ($row = mysql_fetch_assoc($result)) {
	$produk['URL'][] = $row['URL'];
	$produk['DESKRIPSI_GAMBAR'][] = $row['DESKRIPSI_GAMBAR'];
}

$result = $kelola_technopreneur->select_technopreneur($produk['ID_TECHNOPRENEUR']);

while ($row = mysql_fetch_assoc($result)) {
	//$produk['ID_TECHNOPRENEUR']=$row['ID_TECHNOPRENEUR'];
	$produk['NAMA'] = $row['NAMA'];
	$produk['USERNAME'] = $row['USERNAME'];
	$produk['NO_TELP'] = $row['NO_TELP'];
	//var_dump($row);
}

$result = $kelola_review->select_review_confirmed($id_produk);

while ($row = mysql_fetch_assoc($result)) {
	$produk['REVIEW'][] = $row['REVIEW_PRODUK'];
	$produk['WAKTU_REVIEW'][] = $row['WAKTU'];
}

//var_dump($produk);
?>

<html>
  <head>
    <title>Smart Commerce</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
	<style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
    </style>
    <link href="../css/bootstrap-responsive.min.css" rel="stylesheet">
	<script src="../js/jquery-1.7.2.min.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="../js/autoNumeric-1.7.5.js"></script>
</head>
<body>
	<?php include 'header_guest.php'; ?>
	  <div class="container-fluid">
	  <div class="row-fluid">
		<div class="span12">
			<li class="span8">
				<div id="myCarousel" class="carousel slide">
				  <!-- Carousel items -->
				  <div class="carousel-inner" >
				  <?php
					if(!isset($produk['URL'])){
						echo '<div class="active item" style="align:bottom;width:743px;height:400px;">';
						echo '<center><img src="../images/no_image.jpg" class="img-rounded" style="align:middle;max-width:743px;max-height:400px;"></center>';
						echo '</div>';
					}
					else{
						for($i = 0;$i < count($produk['URL']); $i++){
							if($i == 0) echo '<div class="active item" style="align:bottom;width:743px;height:400px;">';
							else echo '<div class="item" style="align:bottom;width:743px;height:400px;">';
							echo '<center><img src="../'.$produk['URL'][$i].'" class="img-rounded" style="align:middle;max-width:743px;max-height:400px;"></center>';
							echo '<div class="carousel-caption">';
							echo '<p>'.$produk['DESKRIPSI_GAMBAR'][$i].'</p>';
							echo '</div>';
							echo '</div>';
						}
					}
					?>
				  </div>
				  <!-- Carousel nav -->
				  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
				  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
				</div>
			</li>
		<li class="span3">
		  <td><h1><strong>Harga</h1></strong></td>
		  <br>
		  <td><h3 class="text-info">Rp. <span id="harga"></span></h3></td>
		  <br><br>
		  <!--Body content-->
		  <p><strong>Berminat? Hubungi</strong></p><td><h3 class="text-warning"><?php echo $produk['NO_TELP']; ?></h3></td>
		</li>
		</div>
		<p>
		<tr>
			<td><strong style="padding-top:20px;">Dijual oleh</strong></td>
			<td>:</td>
			<td><a href="tampil_profil_guest.php?id=<?php echo $produk['ID_TECHNOPRENEUR']; ?>"><?php echo $produk['USERNAME']; ?></a> (<?php echo $produk['NAMA']; ?>)</td>
		</tr>
		<br>
		<tr>
			<td><strong>Deskripsi Gambar</strong></td>
			<td>:</td>
			<td><?php echo $produk['DESKRIPSI_PRODUK']; ?></td>
		</tr>
		<br><br><br>
		<div>
		<legend id="review_produk"><strong>Review Produk</strong></legend>
		  <br>
		  <form action="" method="post">
			<div>
				<div class="control-group">
					<label class="control-label" for="inputEmail">Email*</label>
					<div class="controls">
					  <input style="width:450px; height:30px" type="email" id="inputEmail" name="email" placeholder="ex: email@domain.com" required="required">
					</div>
			  </div>
			<div class="control-group">
				<label class="control-label" for="inputReview">Review Produk</label>
				<div class="controls">
				  <textarea class="input-xlarge" rows="5" name="review" style="width:450" required="required" placeholder="Masukkan review produk..."></textarea><br>
				</div>
			  </div>
			  <div class="control-group">
				<div class="controls">
				  <button type="submit" class="btn">Submit</button>
				  <button type="reset" class="btn">Batal</button>
				</div>
				</div>
			</div>
			</form>
		</div>
		<div>
		<br>
		<table class="table table-bordered" style="width:600;" border="1" cellspacing="0" cellpadding="2">
		<?php
		if(!isset($produk['REVIEW'])){
			echo '<a href="#review_produk" class="muted">Belum ada review</a>';
		}
		else{
			for($i = 0; $i < count($produk['REVIEW']); $i++){
				echo '<tr>';
				echo '<td><small class="muted">'.$produk['WAKTU_REVIEW'][$i].'</small><br>'.$produk['REVIEW'][$i].'</td>';
				echo '</tr>';
			}
		}
		?>
		</table>
		</div>
	  </div>
	</div>
	<input id="hid" type="hidden" />
	<script>
	$(document).ready(function(){
		$('#hid').autoNumeric({
			aSep:'.',
			dGroup:'3',
			aDec:',',
			vMax:'999999999999',
			mDec:'0'
		});
		$('#hid').autoNumericSet(<?php echo $produk['HARGA']; ?>);
		$('#harga').text($('#hid').val());
	});

	</script>
<?php include 'footer_guest.php'; ?>
	</body>
</html>

